package com.leetcood;

public class LargestNumber {
	public static void main(String[] args) {
		int[] num = { 3, 9, 6, 67, 15, 20 };
		String lagestNum = largestNumber(num);
		System.out.println(lagestNum);
		System.out.println(lagestNum.length());
	}
	public static String largestNumber(int[] nums) {
		String[] array = new String[nums.length];
		for (int i = 0; i < nums.length; i++) {
			array[i] = String.valueOf(nums[i]);
		}	
		String temp;
		for (int i = 0; i < array.length; i++) {
			for (int j = i + 1; j < array.length; j++) {
				if ((array[i] + array[j]).compareTo(array[j] + array[i]) < 0) {
					temp = array[i];
					array[i] = array[j];
					array[j] = temp;
				}
			}
		}
		if (array[0].equals("0")) {
			return "0";
		} else {
			return String.join("", array);
		}
	}
}